package com.dong.springboot.rabbitmq.Topic;

import com.dong.springboot.rabbitmq.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

/**
 * @author: dong peng
 * @date: 2019/2/20 10:58
 * @description:  主题模式
 *
 * 消息发送到没有队列绑定的交换机时，消息将丢失，
 * 因为，交换机没有存储消息的能力，消息只能存在在队列中
 */

public class SendTopic {

    public static void main(String[] args) throws IOException, InterruptedException {

        String EXCHANGE_NAME = "test_exchange_fanout";

        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        // 声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

        String str = "Hello World!";
        channel.basicPublish(EXCHANGE_NAME,"", null, str.getBytes());

        System.out.println("交换机: " + str);
        Thread.sleep(500);

        channel.close();
        connection.close();

    }
}
